package com.jiepos.mpos.pay.quickpay.service.huiepay;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import com.hy.pmp.client.DefaultQuickPayClient;
import com.hy.utils.JsonUtil;
import com.jiepos.mpos.common.constant.SystemConstant;
import com.jiepos.mpos.core.util.GlobalUtils;

/**
 * 2.3.3　快捷确认支付-1251
 * @author Izie
 *
 */
public class Req1251Business {
	JsonUtil jsonUtil = new JsonUtil();
	public static String assembleMsgBody(DefaultQuickPayClient client, Map<String, String> dataMap) throws UnsupportedEncodingException{
		Map<String,Object> kv =new HashMap();
		kv.put("tran_cd", "1251");  //交易类型
		kv.put("prod_cd", GlobalUtils.getPayConfProperty("huiepay.pay.prod_cd")); //产品编码T1:1140  T0:1171
		kv.put("biz_cd", GlobalUtils.getPayConfProperty("huiepay.pay.biz_cd"));  //0000026业务编码
		kv.put("chn_ins_id_cd", GlobalUtils.getPayConfProperty("huiepay.pay.chn_ins_id_cd"));  //密钥机构号
		kv.put("ins_id_cd", GlobalUtils.getPayConfProperty("huiepay.pay.ins_id_cd"));  //机构代码
		kv.put("mcht_cd", GlobalUtils.getPayConfProperty("huiepay.pay.mcht_cd"));  //商户号
		kv.put("tran_dt_tm", dataMap.get("loc_dt") + dataMap.get("loc_ts"));
		kv.put("order_id", dataMap.get("loc_trace_no")); //20170717000006,20170717000015
		kv.put("user_id", dataMap.get("trf_mchnt_cd"));  //会员号
		kv.put("order_desc", "");
		kv.put("req_reserved", "");
		kv.put("check_flg", "1111000000");
		kv.put("risk_inf", "");
		
		Map<String,Object> customer_kv =new HashMap<String,Object>();
		customer_kv.put("cert_tp", "01");  //证件类型
		customer_kv.put("cert_id", dataMap.get("certificate_no"));  //证件号码
		customer_kv.put("customer_nm", dataMap.get("real_name"));  //姓名
		customer_kv.put("phone_no", dataMap.get("phone"));  //手机号
		customer_kv.put("sms_code", dataMap.get("verify_code"));  //短信验证码
		customer_kv.put("cvn2", dataMap.get("cvv2"));  //CVN2
		String month = dataMap.get("exptm").substring(0,2);
		String year = dataMap.get("exptm").substring(2, dataMap.get("exptm").length());
		customer_kv.put("expired",year + month);  //有效期
		customer_kv.put("pin", "");  //持卡人密码
		
		String customer_json = JsonUtil.toJsonByObj(customer_kv);
		String customer_encrypt = client.encrypt(customer_json, SystemConstant.UTF_ENCODING); //对银行卡验证信息及身份信息加密
		
		kv.put("customer_info", customer_encrypt);
		
		return JsonUtil.toJsonByObj(kv);
	}
}
